import Dep from "./Dep.js"
import defineReactive from './defineReactive.js'
export default function observe(value, asRootData) {
    let ob = new Observer(value)
    if (asRootData && ob) {
        ob.vmCount++
    }
    return ob
}

export class Observer {
    constructor(value) {
        this.value = value
        this.dep = new Dep()
        this.vmCount = 0
        // def(value, '__ob__', this)
        if (Array.isArray(value)) {
            // if (hasProto) {
            //     protoAugment(value, arrayMethods)
            // } else {
            //     copyAugment(value, arrayMethods, arrayKeys)
            // }
            // this.observeArray(value)
        } else {
            this.walk(value)
        }
    }

    walk(obj) {
        const keys = Object.keys(obj)
        for (let i = 0; i < keys.length; i++) {
            defineReactive(obj, keys[i])
        }
    }

    observeArray(items) {
        for (let i = 0, l = items.length; i < l; i++) {
            observe(items[i])
        }
    }
}
